class Paths {
  delegate = null;
  _commands = null;
  rect(e) {
    let t = this,
      n = [e.x, e.y, e.width, e.height];
    t.addCommand("R:" + n.join(","));
  }
  circle(e) {
    let t = this,
      n = [e.center.x, e.center.y, e.radius, 0, Math.PI * 2];
    t.addCommand("A:" + n.join(","));
  }
  moveTo(e, t) {
    let n = this,
      r = [e, t];
    n.addCommand("M:" + r.join(","));
  }
  lineTo(e, t) {
    let n = this,
      r = [e, t];
    n.addCommand("L:" + r.join(","));
  }
  arc(e, t, n, r, i, s) {
    let o = this,
      u = [];
    for (let a = 0; a < arguments.length; a++) u.push(arguments[a]);
    u.length < 5 && ((u[3] = 0), (u[4] = Math.PI * 2)),
      o.addCommand("A:" + u.join(","));
  }
  arcTo(e, t, n, r, i) {
    let s = this,
      o = [e, t, n, r, i];
    s.addCommand("AT:" + o.join(","));
  }
  closePath = function () {
    let e = this;
    e.addCommand("C");
  };
  commands() {
    let e = this;
    return e._commands == null && (e._commands = []), e._commands;
  }
  clearCommands() {
    let e = this;
    (e._commands = []), e.delegate != null && e.delegate.onPathChanged(e);
  }
  operationMap(e) {
    let t = null;
    switch (e) {
      case "M":
        t = "moveTo";
        break;
      case "L":
        t = "lineTo";
        break;
      case "A":
        t = "arc";
        break;
      case "AT":
        t = "arcTo";
        break;
      case "R":
        t = "rect";
        break;
      case "C":
        t = "closePath";
    }
    return t;
  }
  addCommand(e) {
    let t = this,
      n = e.split("|");
    for (let r = 0; r < n.length; r++) {
      let i = n[r],
        s = i.split(":"),
        o = t.operationMap(s[0]);
      if (o != null) {
        let u = s.length > 1 ? s[1].split(",") : [];
        for (let a = 0; a < u.length; a++) u[a] = parseFloat(u[a]);
        let f = {
          o: o,
          p: u,
        };
        t.commands().push(f);
      }
    }
    t.delegate != null && t.delegate.onPathChanged(t);
  }
  clone() {
    let t = this,
      n = new Paths();
    return (n._commands = t.commands().slice()), n;
  }
}

export default Paths;
